// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueDND from 'awe-dnd'
import Axios from 'axios'
import VeLine from 'v-charts/lib/line.common'
import VeRing from 'v-charts/lib/ring.common'
import VueI18n from 'vue-i18n'

import de from './assets/lang/de'
import zh from './assets/lang/zh'

import en from './assets/lang/en'
import it from './assets/lang/it'
import da from './assets/lang/da'
import fr from './assets/lang/fr'
import nl from './assets/lang/nl'
import pt from './assets/lang/pt'
import sv_SE from './assets/lang/sv-SE'
import es from './assets/lang/es'

import elementDeLocale from 'element-ui/lib/locale/lang/de' // element-ui lang
import elementZhLocale from 'element-ui/lib/locale/lang/zh-CN' // element-ui lang

import elementen from 'element-ui/lib/locale/lang/en'// element-ui 英文
import elementit from 'element-ui/lib/locale/lang/it'// element-ui 意大利
import elementda from 'element-ui/lib/locale/lang/da'// element-ui 丹麦
import elementfr from 'element-ui/lib/locale/lang/fr'// element-ui 法语
import elementnl from 'element-ui/lib/locale/lang/nl'// element-ui 荷兰语
import elementpt from 'element-ui/lib/locale/lang/pt'// element-ui 葡萄牙
import elementsv_SE from 'element-ui/lib/locale/lang/sv-SE'// element-ui 瑞典
import elementes from 'element-ui/lib/locale/lang/es'// element-ui 西班



import * as filter from './filter'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
Vue.config.productionTip = false
NProgress.configure({ showSpinner: false }) // NProgress Configuration
Object.keys(filter).forEach(key => {
  Vue.filter(key, filter[key])
})

Vue.prototype.$axios = Axios
Vue.prototype.$REQ_URL = 'http://hiroaus.huaqiaobang.com/index.php?ctrl='
Vue.prototype.$IMG_REQ_URL = 'http://order.huaqiaobang.com/index.php?ctrl='
Vue.prototype.$PAY_MENT='http://120.24.235.202:8080/finance/FMWeChatPay?'
Vue.use(ElementUI, {
  i18n: (key, value) => i18n.t(key, value)
  
})
Vue.use(VueDND)
Vue.use(VueI18n)
Vue.component(VeLine.name, VeLine)
Vue.component(VeRing.name, VeRing)
/* eslint-disable no-new */

// 语言包插件
const i18n = new VueI18n({
  silentTranslationWarn: true,
  
  locale: 'zh-CN', // 默认德语
  messages: {
    // 德语
    'de': {
      ...de,
      ...elementDeLocale
    },
    // 中文
    'zh-CN': {
      ...zh,
      ...elementZhLocale
    },

    // 英文
    'en': {
      ...en,
      ...elementen
    },
    // // 意大利
    'it': {
      ...it,
      ...elementit
    },
    // 丹麦
    'da': {
      ...da,
      ...elementda
    },
    // 法语
    'fr': {
      ...fr,
      ...elementfr
    },
    // 荷兰语
    'nl': {
      ...nl,
      ...elementnl
    },
    // 葡萄牙
    'pt': {
      ...pt,
      ...elementpt
    },
    // 瑞典
    'sv-SE': {
      ...sv_SE,
      ...elementsv_SE
    }, // 西班牙
    'es': {
      ...es,
      ...elementes
    },  
      
  }
})

// 登录拦截
router.beforeEach((to, from, next) => {
  // start progress bar
  NProgress.start()
  if (to.meta.requireAuth) {
    const shopId = sessionStorage.getItem('shopId')
    if (shopId) {
      next()
    } else {
      Vue.prototype.$message({
        type: 'warning',
        message: '请登录后访问'
      })
      next({
        path: '/Login'
      })
      NProgress.done()
    }
  } else {
    if (to.path === '/Login') {
      sessionStorage.removeItem('shopId')
    }
    next()
  }
})

router.afterEach(() => {
  // finish progress bar
  NProgress.done()
})
new Vue({
  el: '#app',
  router,
  i18n,
  components: { App },
  template: '<App/>'
})
